package montaltoFood
import scala.collection.immutable.HashMap
import montaltoUtils._
/**
 * Created by IntelliJ IDEA.
 * User: Andrew Montalto
 * Date: Apr 19, 2010
 * Time: 12:34:24 PM
 * To change this template use File | Settings | File Templates.
 */

/**
 * 
 */

class FoodFlyWeightFactory(){
  private val foodMap = HashMap(
    "meat"->new Meat(),
    "grain"->new Grain(),
    "mullet"->new Mullet(),
    "no food"->new NoFood() )

  def getFood(foodType:String):Food = {
         return foodMap(foodType)
  }
  
}

object FoodFlyWeightFactory {
  lazy val INSTANCE = new FoodFlyWeightFactory();
  def apply() = INSTANCE
}

trait Food {
  def getCalories:Int
}

class Meat extends Food{
  private val calories = 6
  override def getCalories:Int = {return calories }
}
class Grain extends Food{
  val calories = 4
  override def getCalories:Int = {return calories }
}

class Mullet extends Food{
 val calories = 2
 override def getCalories:Int = {return calories }

}
class NoFood extends Food{
  val calories = 0
  override def getCalories:Int = {return calories }
}
object  RandomFood{
  val TOTAL_FOOD_MOD = 4;
  def get():Food = {
    val foodFac = FoodFlyWeightFactory.INSTANCE
    genNumber match {
      case 0 => return foodFac.getFood("meat")
      case 1 => return foodFac.getFood("mullet")
      case 2 => return foodFac.getFood("grain")
      case 3 => return foodFac.getFood("no food")
    }
    return null

  }
  
  def genNumber:Int = {
    return RandomSingleton.INSTANCE.nextPosInt(TOTAL_FOOD_MOD )
  }
}
